package com.mall.mymall.controller;


import com.mall.mymall.common.Result;
import com.mall.mymall.dao.dto.AdminDto;
import com.mall.mymall.dao.entity.Administrators;
import com.mall.mymall.service.AdministratorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;


import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 十里坡
 * @since 2025-03-06
 */
@RestController
@RequestMapping("/administrators")
public class AdministratorsController {

    @Autowired
    AdministratorsService administratorsService;

    @PostMapping("/login")
    public Result<AdminDto> login(@RequestBody AdminDto adminDto) {
        try {
            return Result.success(administratorsService.adminLogin(adminDto));
        } catch (Exception e) {
            return Result.fail(e.getMessage());
        }

    }

    @PostMapping("/update/nickname")
    public Result<AdminDto> updateNickname(@RequestBody AdminDto adminDto) {
        try {
            return Result.success(administratorsService.updateNickName(adminDto));
        }catch (Exception e){
            return Result.fail(e.getMessage());
        }
    }

    @PostMapping("/update/password")
    public Result<AdminDto> updatePassword(@RequestBody AdminDto adminDto) {
        try {
            return Result.success(administratorsService.updatePassword(adminDto));
        }catch (Exception e){
            return Result.fail(e.getMessage());
        }
    }

    @PostMapping("/list")
    public Result<List<Administrators>> list(@RequestBody AdminDto adminDto) {
        try {
            return Result.success(administratorsService.queryList(adminDto));
        }catch (Exception e){
            return Result.fail(e.getMessage());
        }
    }

    @PostMapping("/update/info")
    public Result<List<Administrators>> updateInfo(@RequestBody AdminDto adminDto) {
        try {
            return Result.success(administratorsService.updateInfo(adminDto));
        } catch (Exception e) {
            return Result.fail(e.getMessage());
        }
    }

    @PostMapping("/update/avatarUrl")
    public Result<AdminDto> updateAvatarUrl(@RequestBody AdminDto adminDto) {
        try {
            return Result.success(administratorsService.updateAvatarUrl(adminDto));
        }catch (Exception e){
            return Result.fail(e.getMessage());
        }
    }
}

